<?php
/**
 * Description of UpdatePwdController
 * 用户个人密码修改
 * @author etpasse
 */
require_rewrite(MODULE_ROOT . "manager/admin/LogManager.class.php");
class UpdatePwdController extends BaseController {

    private $method;
    //private $left_meun;
    public function __construct() {
        parent::__construct();
        //取得页面访问方式
        $this->method = Handler_http::getMethod();
    }

    /**
     * 密码修改
     */
    public function upPwd(){
        header("Content-type:text/html;charset=utf-8");
        $auth_up=new ManagingModule($this->user['id']);
        $pwd_arr= Handler_validate::getExpressions();
        if($this->method =="POST"){
            $oldpwd = $_POST['oldpassword'];
            $pwd = $_POST['password'];
            if(!preg_match($pwd_arr['str'], $pwd) || strlen($pwd)!=intval($pwd_arr['length'])){
                   Handler_tool::alertAndRedirect('请输入指定格式组成的密码！', HTTPFILEURL.'/updatepwd/upPwd/');
             }
            $return=$auth_up->auth_sql_user_pwd($oldpwd, $pwd);
            if($return ==2){
                Handler_tool::alertAndRedirect('原密码填写错误，请重新输入！', HTTPFILEURL.'/updatepwd/upPwd/');
            }elseif($return ==1){
                LogManager::writeAdminModifyLog($this->user['id'],$this->user['username'],$this->user['username'].'修改个人密码成功');
                Handler_http::delSession('txtUsername');
                Handler_http::delSession('txtPassword');
                Handler_http::delSession('PHPSESSID');
                Handler_http::delSession('PHPTYPEID');
                exit(Handler_tool::alertAndRedirectTop('用户密码修改成功,自动退出后请用新密码登录！', HTTPFILEURL.'/login/'));
            }else{
                LogManager::writeAdminModifyLog($this->user['id'], $this->user['username'], $this->user['username'].'修改个人密码失败');
                Handler_tool::alertAndRedirect('密码修改失败，请重新输入！', HTTPFILEURL.'/updatepwd/upPwd/');
            }
        }
        $this->tpl->assign('pwdTxt',$pwd_arr);
        $this->tpl->display("updatepwd/updatePassword.html");
    }
}

?>